package ip.ejb.entity;
/***********************************************************************
 * Module:  MovieBean.java
 * Author:  mojsilo
 * Purpose: Defines the Class MovieBean
 ***********************************************************************/

import ip.ejb.sequence.SequenceSessionLocal;
import ip.ejb.sequence.SequenceSessionLocalHome;

import java.sql.Date;
import java.sql.Time;
import java.util.Collection;

import javax.ejb.CreateException;
import javax.ejb.EntityContext;
import javax.naming.InitialContext;

/**
 * @ejb.bean 
 * 	cmp-version="2.x"
 *  name="Movie"
 *  type="CMP"
 *  jndi-name="ip/ejb/entity/Movie"
 *  local-jndi-name="ip/ejb/entity/MovieLocal"
 *  reentrant="false"
 *  
 * @ejb.finder
 *   signature="java.util.Collection findAll()"
 *   query="SELECT OBJECT(a) FROM Movie a"
 *   method-intf="LocalHome"
 *  
 * @ejb.persistence
 * 	table-name="movie"
 * 
 * @ejb.transaction
 * 	type="Required"
 * 
 * @jboss.table-name
 * 	table-name="movie"
 * 
 * @jboss.create-table
 * 	create="true"
 * 
 * @jboss.remove-table
 * 	remove="false"
 */
public abstract class MovieBean implements javax.ejb.EntityBean
{
	private EntityContext ejbContext = null;
	private SequenceSessionLocal sequenceSession = null;

	/**
	 * @ejb.create-method view-type="both"
	 */
	public MoviePK ejbCreate(CategoryLocal category, CountryLocal country, LanguageLocal language, String originalTitle, String translatedTitle, String director, String producer,int year, String description, Time length, int quantity, float price) throws CreateException {

		setMovieId(sequenceSession.getNextValue("Movie"));
		setOriginalTitle(originalTitle);
		setTranslatedTitle(translatedTitle);
		setDirector(director);
		setDescription(description);
		setLength(length);
		setPrice(price);
		setProducer(producer);
		setQuantity(quantity);
		setYear(year);

		return null;
	}   

	public void ejbPostCreate(CategoryLocal category, CountryLocal country, LanguageLocal language, String originalTitle, String translatedTitle, String director, String producer,int year, String description, Time length, int quantity, float price) throws CreateException{
		setCategory(category);
		setCountry(country);
		setLanguage(language);
	}
	
	public void setEntityContext(EntityContext ctx) throws javax.ejb.EJBException
	{
		SequenceSessionLocalHome home = null;
		Object obj = null;
		this.ejbContext = ctx;
		try {
			obj = (new InitialContext()).lookup("ejb/util/SequenceSessionLocal");
			home = (SequenceSessionLocalHome) obj;
			sequenceSession = home.create();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	public void unsetEntityContext() throws javax.ejb.EJBException
	{
		   this.ejbContext = null;
		   try {
			   sequenceSession.remove();
		   } catch (Exception ex) {
			   ex.printStackTrace();
		   }
	}

	/**
	 * @ejb.persistence column-name="movie_id"
	 * @ejb.interface-method view-type="both"
	 * @ejb.pk-field
	 * @jboss.jdbc-type type="BIGINT"
	 * @jboss.sql-type  type="BIGINT(20)"
	 */
	public abstract long getMovieId();

	/**
	 * @ejb.interface-method view-type="local"
	 */
	public abstract void setMovieId(long movieId);

	/**
	 * @ejb.persistence column-name="original_title"
	 * @ejb.interface-method view-type="both"
	 * @jboss.jdbc-type type="VARCHAR"
	 * @jboss.sql-type  type="VARCHAR(40)"
	 */
	public abstract String getOriginalTitle();

	/**
	 * @ejb.interface-method view-type="local"
	 */
	public abstract void setOriginalTitle(String originalTitle);

	/**
	 * @ejb.persistence column-name="translated_title"
	 * @ejb.interface-method view-type="both"
	 * @jboss.jdbc-type type="VARCHAR"
	 * @jboss.sql-type  type="VARCHAR(40)"
	 */
	public abstract String getTranslatedTitle();

	/**
	 * @ejb.interface-method view-type="local"
	 */
	public abstract void setTranslatedTitle(String translatedTitle);

	/**
	 * @ejb.persistence column-name="price"
	 * @ejb.interface-method view-type="both"
	 * @jboss.jdbc-type type="DECIMAL"
	 * @jboss.sql-type  type="DECIMAL(8,2)"
	 */
	public abstract float getPrice();

	/**
	 * @ejb.interface-method view-type="local"
	 */
	public abstract void setPrice(float price);

	/**
	 * @ejb.persistence column-name="producer"
	 * @ejb.interface-method view-type="both"
	 * @jboss.jdbc-type type="VARCHAR"
	 * @jboss.sql-type  type="VARCHAR(30)"
	 */
	public abstract String getProducer();

	/**
	 * @ejb.interface-method view-type="local"
	 */
	public abstract void setProducer(String producer);
	
	/**
	 * @ejb.persistence column-name="director"
	 * @ejb.interface-method view-type="both"
	 * @jboss.jdbc-type type="VARCHAR"
	 * @jboss.sql-type  type="VARCHAR(30)"
	 */
	public abstract String getDirector();

	/**
	 * @ejb.interface-method view-type="local"
	 */
	public abstract void setDirector(String director);

	/**
	 * @ejb.persistence column-name="year"
	 * @ejb.interface-method view-type="both"
	 * @jboss.jdbc-type type="INTEGER"
	 * @jboss.sql-type  type="INTEGER"
	 */
	public abstract int getYear();

	/**
	 * @ejb.interface-method view-type="local"
	 */
	public abstract void setYear(int year);

	/**
	 * @ejb.persistence column-name="description"
	 * @ejb.interface-method view-type="both"
	 * @jboss.jdbc-type type="VARCHAR"
	 * @jboss.sql-type  type="VARCHAR(255)"
	 */
	public abstract String getDescription();

	/**
	 * @ejb.interface-method view-type="local"
	 */
	public abstract void setDescription(String description);

	/**
	 * @ejb.persistence column-name="length"
	 * @ejb.interface-method view-type="both"
	 * @jboss.jdbc-type type="TIME"
	 * @jboss.sql-type  type="TIME"
	 */
	public abstract Time getLength();

	/**
	 * @ejb.interface-method view-type="local"
	 */
	public abstract void setLength(Time length);
	
	/**
	 * @ejb.persistence column-name="quantity"
	 * @ejb.interface-method view-type="both"
	 * @jboss.jdbc-type type="INTEGER"
	 * @jboss.sql-type  type="INTEGER"
	 */
	public abstract int getQuantity();

	/**
	 * @ejb.interface-method view-type="local"
	 */
	public abstract void setQuantity(int quantity);


	/**
	 * @ejb.interface-method view-type="local"
	 * @ejb.relation
	 *   name="Movie-OrderItem"
	 *   role-name="Movie-is-OrderItem"
	 *   target-ejb="OrderItem"
	 */
	public abstract Collection getOrderItem();

	/**
	 * @ejb.interface-method view-type="local"
	 */
	public abstract void setOrderItem(Collection orderItems);
	
	/**
	 * @ejb.interface-method view-type="local"
	 * @ejb.relation
	 *   name="Movie-Category"
	 *   role-name="Movie-belongs-to-Movie-Category"
	 *   cascade-delete="yes"
	 * @jboss.relation
	 *   fk-constraint="true"
	 *   fk-column="categoryId"
	 *   related-pk-field="categoryId"
	 */
	public abstract CategoryLocal getCategory();
	/**
	 * @ejb.interface-method view-type="local"
	 */
	public abstract void setCategory(CategoryLocal category);
	
	/**
	 * @ejb.interface-method view-type="local"
	 * @ejb.relation
	 *   name="Movie-Country"
	 *   role-name="Movie-is-from-Country"
	 *   cascade-delete="yes"
	 * @jboss.relation
	 *   fk-constraint="true"
	 *   fk-column="countryId"
	 *   related-pk-field="countryId"
	 */
	public abstract CountryLocal getCountry();
	/**
	 * @ejb.interface-method view-type="local"
	 */
	public abstract void setCountry(CountryLocal country);

	/**
	 * @ejb.interface-method view-type="local"
	 * @ejb.relation
	 *   name="Movie-Language"
	 *   role-name="Movie-main-Language"
	 *   cascade-delete="yes"
	 * @jboss.relation
	 *   fk-constraint="true"
	 *   fk-column="languageId"
	 *   related-pk-field="languageId"
	 */
	public abstract LanguageLocal getLanguage();
	/**
	 * @ejb.interface-method view-type="local"
	 */
	public abstract void setLanguage(LanguageLocal language);
	
	/**
	 * @ejb.interface-method view-type="local"
	 * @ejb.relation
	 *   name="Movie-Subtitles"
	 *   role-name="Movies-Subtitles"
	 *   target-ejb="MovieSubtitles"
	 */
	public abstract Collection getMovieSubtitles();

	/**
	 * @ejb.interface-method view-type="local"
	 */
	public abstract void setMovieSubtitles(Collection movieSubtitles);
	
	public void ejbActivate() throws javax.ejb.EJBException{}
	public void ejbLoad() throws javax.ejb.EJBException{}
	public void ejbPassivate() throws javax.ejb.EJBException{}
	public void ejbRemove() throws javax.ejb.RemoveException, javax.ejb.EJBException{}
	public void ejbStore() throws javax.ejb.EJBException{}

}